<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="../../../utils/layui/css/layui.css">
		<style>
			*{
				line-height: 1.8em;
			}
			#linkHtml{
				padding-left: 5px;
			}
			.chind{
				padding-left: 5px;
			}
		</style>
	</head>
	<body>
		<form class="layui-form" action="" onsubmit="return false;">
		  <input type="hidden" name="_method" id="_method" value="check" />
		  <div class="layui-form-item">
		    <label class="layui-form-label">连接地址</label>
		    <div class="layui-input-block">
		      <input type="text" name="host" lay-verify="required" autocomplete="off" placeholder="例如:http://192.168.1.3:9200/" class="layui-input" onchange="check(this)">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">索引选择</label>
		    <div class="layui-input-block">
			  <select name="index" style="height: 38px;" id="index" lay-ignore>
				  <option value="">请选择</option>
			  </select>
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <div class="layui-input-block">
		      <button type="submit" class="layui-btn" lay-submit="" lay-filter="formDemo">连接</button>
		    </div>
		  </div>
		</form>
		<script src="/admin/utils/layui/layui.js" charset="utf-8"></script>
		<script src="/admin/utils/layui/config.js" charset="utf-8"></script>
		<script>
			layui.use(['layer','form','helper'], function(){
				var $ = layui.$;
				var form = layui.form;
				window.check = function(obj){
					ajax_request('/admin/websoftware-es', 'POST', 'host='+obj.value+'&_method=check', function(res){
						if(res.data == false){
							alert("当前es没有任何index");
							return false;
						}
						var ophtml = '<option value="">请选择</option>';
						for(i in res.data){
							ophtml += '<option value="'+res.data[i]['index']+'">'+res.data[i]['index']+'</option>';
						}
						$("#index").html(ophtml);
					});
				}
				form.on('submit(formDemo)', function(data){
					ajax_request('/admin/websoftware-es', 'POST', data.field, function(res){
						json = json_encode(data.field);
						setcookie('esconf', json);
						$(window.parent.document).find("#iframeContent").attr("src",'./elasticsearch/finder.html'); 
						//刷新指定框架
					});
					//存cookie
				})
				
			});
		</script>
	</body>
</html>
